<?php

/**
 * quiz actions.
 *
 * @package    demo
 * @subpackage quiz
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 9301 2008-05-27 01:08:46Z dwhittle $
 */
class quizActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex($request)
  {
    $this->datos = TypeQuestionPeer::doSelect(new Criteria());
  }
  
  public function executeTest($request)
  {
  	$type_question = $request->getParameter('type');
  	
  	$criteria      = new Criteria();
  	
  	$criteria->add(QuestionPeer::ID_TYPE_QUESTION , $type_question);//estaba comentarizado
  	
  	$elementos     = QuestionPeer::doCount($criteria);
  	
  	if ($elementos < 5)
  	{
  		$this->mensaje;
  	}
  	else
  	{
	  	$filtradoId    = array($elementos);
	  	$tempId        = array($elementos);
	  	
	  	$filtradoName  = array($elementos);
	  	$tempName      = array($elementos);
	  	
	  	$seleccionados = array();
	  	
	  	$preguntas = QuestionPeer::doSelect($criteria);
	  	
	  	
	  	foreach($preguntas as $pregunta)
	  	{
	  		array_push($filtradoId,$pregunta->getId());
	  		array_push($tempId,$pregunta->getId());
	  		
	  		array_push($filtradoName,$pregunta->getName());
	  		array_push($tempName,$pregunta->getName());
	  	}
	  	
	  	
	  	$this->preguntaAleatoria = array();
	  	$this->idAleatorio = array();
	  	
	  	$seleccionados = array();
	  	$total = 5;
	  	
	  	for ($i = 0; $i <$total ; $i++)
	  	{
	  		
	 		$newE       = count($tempName); 		
	  		$random     = rand(1, $newE-1);
	  		
	  		
	  		if(in_array($tempName[$random] , $seleccionados))
	 		{
	 			$random     = rand(1, $newE-1);
	 	
	 			$total++;
	 		}
	 		else 
	 		{	 			
	 			$this->preguntaAleatoria[$i] = $tempName[$random];
	 			$this->idAleatorio[$i] = $tempId[$random];	 				
	 			array_push($seleccionados,$tempName[$random]);
	 		}	 		
	 		
	  	}
	  	 	
	  	
  	}
  	$this->test =  TypeQuestionPeer::retrieveByPK($type_question);
  }
  
}
